//
// Created by Administrator on 2021/9/30.
//

#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        // 直接算出两个矩形的长和宽
        int width1 = ax2 - ax1, height1 = ay2 - ay1, width2 = bx2 - bx1, height2 = by2 - by1;
        // 算出重叠部分的长和宽
        int overlapWidth = min(ax2, bx2) - max(ax1, bx1), overlapHeight = min(ay2, by2) - max(ay1, by1);
        int overlapArea = max(0, overlapWidth) * max(0, overlapHeight);
        return width1 * height1 + width2 * height2 - overlapArea;
    }
};

int main() {
    Solution solution;
    cout << solution.computeArea(-3, 0, 3, 4, 0, -1, 9, 2) << endl;
    cout << solution.computeArea(-2, -2, 2, 2, -2, -2, 2, 2) << endl;
    return 0;
}